import 'dart:io';

import 'package:path/path.dart' as path;

import '../constants/constants.dart';

class FileUtils {
  static String? getExtension(String? filePath) {
    return (filePath != null && filePath.isNotEmpty)
        ? path.extension(filePath)
        : filePath;
  }

  static String getContentType(String? fileExtension) {
    const contentTypes = {
      '.jpeg': Constants.imageJpeg,
      '.jpg': Constants.imageJpeg,
      '.jfif': Constants.imageJpeg,
      '.png': Constants.imagePng,
      '.pdf': Constants.applicationPdf,
      '.doc': Constants.applicationMSword,
      '.docx': Constants.applicationMSword,
    };

    return contentTypes[fileExtension?.toLowerCase()] ?? Constants.imageJpeg;
  }

  static String fileName(File pickedFile) => pickedFile.path.split('/').last;
}
